package org.airline.impl;

import java.util.List;

import org.airline.dao.IFlightArrangeDao;
import org.airline.entity.FlightArrange;
import org.airline.entity.Message;
import org.airline.entity.PageBean;
import org.springframework.stereotype.Component;

@Component("FlightArrangeDaoImpl")
@SuppressWarnings("all")
public class FlightArrangeDaoImpl extends HibernateDaoImpl implements
		IFlightArrangeDao {

	@Override
	public void FlightArrangInfoSave(FlightArrange flightArrange)
			throws Exception {
		// 航班安排信息插入
		super.save(flightArrange);
	}

	@Override
	public void deleteFlightArrangeInfoById(int id) throws Exception {
		// 删除航班安排信息
		super.delete(FlightArrange.class, id);
	}

	@Override
	public List<FlightArrange> getAllFlightArrange() throws Exception {
		// 查询航班安排信息
		return (List<FlightArrange>) super.find("FROM FlightArrange");
	}

	@Override
	public FlightArrange getFlightArrangeById(int id) throws Exception {
		// 通过ID查询航班安排信息
		return (FlightArrange) super.get(FlightArrange.class, id);
	}

	@Override
	public void updateFlightArrangeInfo(FlightArrange fliArrange)
			throws Exception {
		// 更新航班安排信息
		super.update(fliArrange);
	}

	@Override
	public PageBean queryForPage(int pageSize, int page) throws Exception {
		final String hql = "FROM FlightArrange";
		return super.queryForPage(hql, pageSize, page);
	}

	// 根据安排时间查询前10条记录
	@Override
	public List<FlightArrange> getFlightArrangeByDate() throws Exception {
		String hql = "FROM FlightArrange ORDER BY startDate DESC";
		return (List<FlightArrange>) super.findPageByQuery(hql, 0, 5);
	}

	// 根据地点查询单程航班安排信息
	@Override
	public PageBean querySearchForSingle(int pageSize, int page,
			FlightArrange flightArrange) throws Exception {
		final String hql;
		if (flightArrange.getStartDate().equals("")) {
			hql = "FROM FlightArrange WHERE flight.start_flight = '"
					+ flightArrange.getFlight().getStart_flight()
					+ "' AND flight.end_flight = '"
					+ flightArrange.getFlight().getEnd_flight() + "'";
		} else {
			hql = "FROM FlightArrange WHERE flight.start_flight = '"
					+ flightArrange.getFlight().getStart_flight()
					+ "' AND flight.end_flight = '"
					+ flightArrange.getFlight().getEnd_flight()
					+ "' AND startDate LIKE '% " + flightArrange.getStartDate()
					+ " %'";
		}
		return super.queryForPage(hql, pageSize, page);
	}
	
	//根据关键字分页查询
	@Override
	public PageBean queryForPageByKeyWords(String keyWord, int pageSize,
			int page) throws Exception {
		String hql = "FROM FlightArrange WHERE flight.flight_name = '" + keyWord + "'";
		return super.queryForPage(hql, pageSize, page);
	}

	
	
	
}
